package com.UI;
import java.util.ArrayList;

import com.Model.StudentDBModel;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;
public class EditStudyInfo extends Activity {
	private StudentDBModel model;
	private ArrayList study_info;
	private String[] studyinfodetails;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.edit_study_info);
		
		Bundle extras = getIntent().getExtras();
		final String gname = extras.getString("GroupName");
		
		model = new StudentDBModel(this);
		
		study_info = model.getStudyInfoDetails(gname);
		studyinfodetails =(String[]) study_info.toArray(new String[study_info.size()]);
		String cid = studyinfodetails[0];
		ContentValues values = new ContentValues();
		TextView lblGroupNameFromDB = (TextView) findViewById(R.id.lblGroupNameFromDB);
		lblGroupNameFromDB.setText(studyinfodetails[1]);
		
		EditText txtGroupTime = (EditText) findViewById(R.id.editTxtGroupTime);
		txtGroupTime.setText(studyinfodetails[2]);
		
		EditText txtGroupNotes= (EditText) findViewById(R.id.editTxtGroupNotes);
		txtGroupNotes.setText(studyinfodetails[3]);
		
		
		
		
Button btnStudyInfoSubmit = (Button) findViewById(R.id.btnStudyInfoSubmit);
		
		btnStudyInfoSubmit.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View component) {
				
		 		
				
				ContentValues editedvalues = new ContentValues();
				editedvalues.put("GroupName", gname);
		
				
				EditText txtGroupTime = (EditText) findViewById(R.id.editTxtGroupTime);
				editedvalues.put("GroupTime", txtGroupTime.getText().toString());
		
				EditText txtGroupNotes= (EditText) findViewById(R.id.editTxtGroupNotes);
				if(txtGroupNotes.getText().toString().equals("")){
					editedvalues.put("GroupNotes","No Notes Entered");}
				else {
					editedvalues.put("GroupNotes", txtGroupNotes.getText().toString());}
		
				// use the model to update the data
				model.updateStudyInfo(editedvalues,gname);
				int numStudyInfo = model.getNumStudyInfo();
				// tell the user that study information was updated to the database
				TextView lblResults = (TextView) findViewById(R.id.lblEditStudyInfoResult);
				lblResults.setText(numStudyInfo + " " + getString(R.string.StudyInfoUpdated));
				
				
				
				
				EditStudyInfo.this.finish();
				}
			
		});
		
		//Home and Back Buttons
		Button btnGoBack = (Button) findViewById(R.id.btnBack);
		btnGoBack.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View component) {
				// go back to the pick class event view
				EditStudyInfo.this.finish();
			}
		});
		
		Button btnGoHome = (Button) findViewById(R.id.btnHome);
		btnGoHome.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View component) {
				// go to the home page
				Intent goHome = new Intent(EditStudyInfo.this, HomePage.class);
				startActivity(goHome);
				//finish the activity to return to the calling event
				EditStudyInfo.this.finish();
			}
		});
		
		
		
		
		
		
		
		
		
		
	}	
}